﻿<%@ Page Language="c#" CodeBehind="Set.aspx.cs" AutoEventWireup="false" Inherits="UDS.SubModule.WorkAttendance.SetPage" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head runat="server">
  <title>Set</title>
  <uds:Style runat="server" Href="~/css/BasicLayout.css" />
  <script language="javascript">
  //<!--
  function to_2_digits(v)
  {
    return (v<10) ? "0" + v : v.toString();
  }
  function formatDate(d)
  {
    return d.getFullYear() + "-" + to_2_digits(d.getMonth() + 1) + "-" + to_2_digits(d.getDate());
  }
  function quickSelectDate(type)
  {
	  var beginTime;
	  var endTime;
	  var oneMinute = 60 * 1000;
	  var oneHour = 60 * oneMinute;
	  var oneDay = 24 * oneHour;
	  var oneWeek = 7 * oneDay;
  	
	  var todayDate = new Date();	  
	  if(type == "day")
	  {
		  beginTime = formatDate(todayDate);
		  endTime = beginTime;
	  }
	  else if(type=="week")
	  {
	    var daytoMon = todayDate.getDay() - 1;
		  if(todayDate.getDay() == 0) 
			  daytoMon = 6;
  		
		  todayDate.setTime(todayDate.getTime() - daytoMon * oneDay);  		
		  beginTime = formatDate(todayDate);
  		
		  todayDate.setTime(todayDate.getTime() + 6 * oneDay);  		
		  endTime = formatDate(todayDate);
	  }
	  else if(type=="month")
	  {
		  var dateTo1 = todayDate.getDate() - 1;
  		
		  todayDate.setTime(todayDate.getTime() - dateTo1 * oneDay);
  		beginTime = formatDate(todayDate);

		  todayDate.setMonth(todayDate.getMonth() + 1);
		  todayDate.setTime(todayDate.getTime() - oneDay);
		  endTime = formatDate(todayDate);
	  }

	  document.getElementById("txtBeginTime").value = beginTime;
	  document.getElementById("txtEndTime").value = endTime;
  }

  function checkDutyTime(source, arguments)
  {
	  var ondutytime = document.getElementById('tbx_OnDutyTime').value;
	  var offdutytime = document.getElementById('tbx_OffDutyTime').value;
	  var begindate = Date.parse('1/1/1900 '+ondutytime);
	  var enddate = Date.parse('1/1/1900 '+offdutytime);
	  if(enddate<begindate)
		  arguments.IsValid = false;
	  else
		  arguments.IsValid = true;
  }

  function checkDutyDate()
  {
	  var begindate = document.getElementById('txtBeginTime').value;
	  var enddate = document.getElementById('txtEndTime').value;
	  if(begindate.replace(' ','')=='' || enddate.replace(' ','')=='')
	  {
		  alert('日期不能为空');
		  return false;
	  }
	  else
	  {
		  if(begindate>enddate)
		  {
			  alert('开始时间不能大于结束时间');
			  return false
		  }
	  }

    // The "xxx" query string parameter is used to avoid page cache.
    var url = "ShowDay.aspx?begintime=" + begindate + "&endtime=" + enddate + "&xxx=" + new Date().valueOf();
	  window.open(url, "", "width=400, height=500, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no"); 
	  return true;
  }
  //-->
  </script>
</head>
<body>
  <form id="Set" method="post" runat="server">
    <ajax:ToolkitScriptManager runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true" />
    <uds:PageTitle runat="server" HintImage="~/DataImages/workadmin2.gif" Title="考勤设置" />
    <table class="GBText" id="Table1" style="border-collapse: collapse; height: 109px" bordercolor="#93bee2" height="109" cellspacing="1" cellpadding="1" width="100%" border="1" designtimedragdrop="56">
      <tr>
        <td style="width: 130px; height: 54px" align="center">考勤日设置</td>
        <td style="height: 54px">
          <table border="0" cellpadding="4" cellspacing="0">
            <tr>
              <td>开始时间：</td>
              <td>
                <uds:DateTextBox runat="server" ID="txtBeginTime" ReadOnly="true" Columns="10" CssClass="inputcss" />
              </td>
              <td>-- 结束时间</td>
              <td>
                <uds:DateTextBox runat="server" ID="txtEndTime" ReadOnly="true" Columns="10" CssClass="inputcss" />
                <asp:CompareValidator runat="server" ControlToCompare="txtBeginTime" Operator="GreaterThanEqual" ErrorMessage="结束时间应该大于开始时间" ControlToValidate="txtEndTime" Display="None" />
              </td>
              <td><asp:RadioButton ID="rbtnthisweek" onclick="quickSelectDate('week');" runat="server" GroupName="quickdate" Text="本周" /><asp:RadioButton ID="rbtnthismonth" onclick="quickSelectDate('month');" runat="server" GroupName="quickdate" Text="本月" /></td>
              <td><input class="buttoncss" title="设置考勤日期" onclick="checkDutyDate()" type="button" value="详细情况" /></td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td style="width: 130px" align="center">设置公司考勤时间</td>
        <td>上班时间
          <asp:TextBox ID="tbx_OnDutyTime" runat="server" CssClass="inputcss" Width="80px" /><asp:RequiredFieldValidator runat="server" ErrorMessage="上班时间不能为空" ControlToValidate="tbx_OnDutyTime" Display="Dynamic" /><asp:RegularExpressionValidator runat="server" ErrorMessage="时间格式错误" ControlToValidate="tbx_OnDutyTime" Display="Dynamic" ValidationExpression="(((0|1)[0-9])|(2[0-3])|([0-9])):([0-5][0-9])" />下班时间
          <asp:TextBox ID="tbx_OffDutyTime" runat="server" CssClass="inputcss" Width="80px" /><asp:RequiredFieldValidator runat="server" ErrorMessage="下班时间不能为空" ControlToValidate="tbx_OffDutyTime" Display="Dynamic" /><asp:RegularExpressionValidator runat="server" ErrorMessage="时间格式错误" ControlToValidate="tbx_OffDutyTime" Display="Dynamic" ValidationExpression="(((0|1)[0-9])|(2[0-3])|([0-9])):([0-5][0-9])" /><asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="下班时间不能早于上班时间" Display="Dynamic" ClientValidationFunction="checkDutyTime" />（时间格式采用09:00或9:00）
          <asp:Button ID="btn_SetTime" runat="server" CssClass="buttoncss" Text=" 保  存"></asp:Button>
        </td>
      </tr>
      <tr>
        <td style="width: 130px" align="center">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
  </form>
</body>
</html>
